package com.fz.aop.login;

import com.fz.security.utils.SecurityUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;


@Service(value = "el")
public class ElPermissionConfig {
    public boolean check(String ...permissions){
        Set<String> elPermissions = SecurityUtils.getUserDetails().getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toSet());
        // 判断当前用户的所有权限是否包含接口上定义的权限 如果管理权限是admin情况则放开就行
        // return elPermissions.contains("admin") || Arrays.stream(permissions).anyMatch(elPermissions::contains);
        return Arrays.stream(permissions).anyMatch(elPermissions::contains);
    }
}
